baubs git
Commit 085ac1a5f780996b2cb7033aa253ecd370873c50
Parents : 3d51992
Author : Jan-Henrik Bruhn <hi@jhbruhn.de>
Date : 2025-12-06T23:39:31+01:00
Fix pattern re-upload after deletion by preserving filename
Fix bug where deleting a cached pattern prevented re-uploading because
the filename was lost. After deletion, the pattern remains visible in
the UI for re-editing and re-uploading, but the upload would silently
fail because displayFileName was empty.
The issue occurred because:
1. Pattern loaded from cache uses resumeFileName (from hook)
2. Local fileName state in FileUpload was never set (empty string)
3. After deletion, resumeFileName is cleared to null
4. displayFileName becomes empty, preventing upload
Solution:
- Add fallback to 'pattern.pes' when pesDataProp exists but no filename
- This ensures re-upload works after deletion while keeping pattern visible
- Pattern data (pesData) persists in App.tsx state for re-editing
Now users can delete a cached pattern and immediately re-upload it
with position adjustments or other modifications.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Changes
2 files changed, 3 insertions(+), 1 deletions(-)
Diff
diff --git a/src/components/FileUpload.tsx b/src/components/FileUpload.tsx
index b9e406a..4cf0031 100644
--- a/src/components/FileUpload.tsx
+++ b/src/components/FileUpload.tsx
@@ -39,7 +39,8 @@ export function FileUpload({
// Use prop pesData if available (from cached pattern), otherwise use local state
const pesData = pesDataProp || localPesData;
- const displayFileName = resumeFileName || fileName;
+ // When resumeFileName is cleared but we still have pesData, preserve the filename
+ const displayFileName = resumeFileName || fileName || (pesDataProp ? 'pattern.pes' : '');
const [isLoading, setIsLoading] = useState(false);
const handleFileChange = useCallback(
diff --git a/src/hooks/useBrotherMachine.ts b/src/hooks/useBrotherMachine.ts
index 699175c..1229b57 100644
--- a/src/hooks/useBrotherMachine.ts
+++ b/src/hooks/useBrotherMachine.ts
@@ -306,6 +306,7 @@ export function useBrotherMachine() {
setResumeFileName(null);
// NOTE: We intentionally DON'T clear setResumedPattern(null)
// so the pattern remains visible in the canvas for re-editing
+ // However, we DO need to preserve pesData in App.tsx for re-upload
await refreshStatus();
} catch (err) {
Served by rngit 1.4.2 - Generated in 0.05s